package com.cx.cloud.web;

import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author onoo
 * @create 2021-12-04
 **/
@RestController
@RequestMapping("hello")
public class HelloController {

    @Resource
    private RestTemplate restTemplate;

    @Bean
    @LoadBalanced
    public RestTemplate initRestTemplate(){
        return new RestTemplate();
    }

    @Resource
    private DiscoveryClient discoveryClient;


    @GetMapping("print")
    public String print(){
//        String resp = restTemplate.getForObject ("http://127.0.0.1:8081/web/hello", String.class);
        String resp = restTemplate.getForObject ("http://cloud-nacos-service01/web/hello", String.class);
        return resp;
    }

}
